<?
if (preg_match("#" . basename(__FILE__) . "#", $_SERVER['PHP_SELF'])) {
	die('This page cannot be called directly.') ;
}

class ajax_email {
	function playme(){
        $code = Url::getParam('code');
        //yêu cầu đặt tên $code=tên của method trong class
        $this->$code();
        if (method_exists($this, $code)) {
            $this->$code();
        }else{
            $this->home();
        }
	}
	
	function home(){
		global $display;
		die("Nothing to do...");
	}
                 
        function del_emails_selected()
        
    {
       
		if(!User::is_login())
		{
			echo "not_login";
			exit;
		}

                if(!User::have_permit("email_delete"))
                {
                    echo "no_perm";
                    exit;
                }
         
        
		$email_ids= Url::get("selected_ids");

		if(is_array($email_ids))
		{
            $error = false;
            
            foreach($email_ids as $id)
            {
                if($id == '-1'){
                    $error = TRUE;
                }else{
                        $mail =	array();
                        $mail['status'] = '-1';
                        Db::update_id('mail_request', $mail, $id);
                }
            }
            
            if($error)
            {
                echo "un_success";
            }
            else{
                echo "success";
            }
		}
		else
		{
                    
            echo "not_item";
            exit;
        }
	}
        
        function del_tuas_selected()
        
    {
       
		if(!User::is_login())
		{
			echo "not_login";
			exit;
		}

                if(!User::have_permit("news_del"))
                {
                    echo "no_perm";
                    exit;
                }
         
        
		$news_ids= Url::get("selected_ids");

		if(is_array($news_ids))
		{
            $error = false;
            
            foreach($news_ids as $id)
            {
                if($id == '-1'){
                    $error = TRUE;
                }else{
                        $news 	= DB::select_id('news', $id);
                        $news['status'] = '-1';
                        $news['user_del'] = User::id();
                        $news['user_del_email'] = User::user_email();
                        Db::update_id('tourist_attractions', $news, $id);
                }
            }
            
            if($error)
            {
                echo "un_success";
            }
            else{
                echo "success";
            }
		}
		else
		{
                    
            echo "not_item";
            exit;
        }
	}
}
?>